package com.lk.ii.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lk.common.annotation.Log;
import com.lk.common.enums.BusinessType;
import com.lk.ii.domain.IiSuggest;
import com.lk.ii.service.IIiSuggestService;
import com.lk.common.core.controller.BaseController;
import com.lk.common.core.domain.AjaxResult;
import com.lk.common.utils.poi.ExcelUtil;
import com.lk.common.core.page.TableDataInfo;

/**
 * 建议意见Controller
 * 
 * @author lk
 * @date 2021-02-05
 */
@Controller
@RequestMapping("/ii/suggest")
public class IiSuggestController extends BaseController
{
    private String prefix = "ii/suggest";

    @Autowired
    private IIiSuggestService iiSuggestService;

    @RequiresPermissions("ii:suggest:view")
    @GetMapping()
    public String suggest()
    {
        return prefix + "/suggest";
    }

    /**
     * 查询建议意见列表
     */
    @RequiresPermissions("ii:suggest:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(IiSuggest iiSuggest)
    {
        startPage();
        List<IiSuggest> list = iiSuggestService.selectIiSuggestList(iiSuggest);
        return getDataTable(list);
    }

    /**
     * 导出建议意见列表
     */
    @RequiresPermissions("ii:suggest:export")
    @Log(title = "建议意见", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(IiSuggest iiSuggest)
    {
        List<IiSuggest> list = iiSuggestService.selectIiSuggestList(iiSuggest);
        ExcelUtil<IiSuggest> util = new ExcelUtil<IiSuggest>(IiSuggest.class);
        return util.exportExcel(list, "suggest");
    }

    /**
     * 新增建议意见
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存建议意见
     */
    @RequiresPermissions("ii:suggest:add")
    @Log(title = "建议意见", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(IiSuggest iiSuggest)
    {
        return toAjax(iiSuggestService.insertIiSuggest(iiSuggest));
    }

    /**
     * 修改建议意见
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        IiSuggest iiSuggest = iiSuggestService.selectIiSuggestById(id);
        mmap.put("iiSuggest", iiSuggest);
        return prefix + "/edit";
    }

    /**
     * 修改保存建议意见
     */
    @RequiresPermissions("ii:suggest:edit")
    @Log(title = "建议意见", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(IiSuggest iiSuggest)
    {
        return toAjax(iiSuggestService.updateIiSuggest(iiSuggest));
    }

    /**
     * 删除建议意见
     */
    @RequiresPermissions("ii:suggest:remove")
    @Log(title = "建议意见", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(iiSuggestService.deleteIiSuggestByIds(ids));
    }
}
